//
//  ZGLSearchVC.m
//  Faker
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZGLSearchVC.h"
#import "ZGLSearchTitleView.h"
#import "ZGLGoodsCollectionViewCell.h"
#import "ZGLChannelCollectionViewCell.h"
#import "ZGLSubDetailsVC.h"
#import "ZGLNewChannelVC.h"
#import "ZGLHTTPTOOL.h"
#import "ZGLSearchTableViewCell.h"
#import "ZGLSearchWebModel.h"
#import "ZGLTopicTypeVC.h"
#import "ZGLTablePicVC.h"
#import "ZGLSubDetModel.h"
#import "ZGLTopicDetModel.h"
#import "ZGLPicVCModel.h"
#import "ZGLOptionsModel.h"
#import "ZGLPhotoVC.h"
#import "ZGLEpisodeVC.h"


@interface ZGLSearchVC () <UISearchBarDelegate, UICollectionViewDataSource, UICollectionViewDelegate, ZGLGoodsCollectionViewCellDelegate, UITableViewDataSource ,UITableViewDelegate, ZGLChannelCollectionViewCellDelegate> {

}

@property (nonatomic, strong) ZGLSearchTitleView *titleView;
@property (nonatomic, strong) UISearchBar *searchBar;
@property (nonatomic, strong) UICollectionView *searchCollectionView;

@property (nonatomic, copy) NSString *searchUrl;
@property (nonatomic, strong) UIView *resultView;
@property (nonatomic, strong) UITableView *resultTableview;
@property (nonatomic, strong) NSMutableArray *channelArr;

@property (nonatomic, strong) NSMutableDictionary *signDic;
@property (nonatomic, strong) NSMutableArray *signArr;


@property (nonatomic, strong) NSIndexPath *tempIndex;


@end

@implementation ZGLSearchVC

- (void)dealloc {
    _searchBar.delegate = nil;
    _searchCollectionView.delegate = nil;
    _searchCollectionView.dataSource = nil;
    _resultTableview.delegate = nil;
    _resultTableview.dataSource = nil;
    [_searchCollectionView removeObserver:self forKeyPath:@"contentOffset"];
    [_titleView.channelButton removeTarget:self action:@selector(button:) forControlEvents:(UIControlEventTouchUpInside)];
    [_titleView.goodsButton removeTarget:self action:@selector(button:) forControlEvents:(UIControlEventTouchUpInside)];
}

- (void)createTableView {
    _resultTableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScaleX * 375, ScaleY * 603) style:(UITableViewStylePlain)];
    _resultTableview.backgroundColor = backColor;
    _resultTableview.delegate = self;
    _resultTableview.dataSource = self;
    [_resultView addSubview:_resultTableview];
    [_resultTableview registerClass:[ZGLSearchTableViewCell class] forCellReuseIdentifier:@"ZGLSearchVC_ZGLSearchTableViewCell"];
    [_resultTableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"soycell"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (_channelArr.count == 0) {
        return 1;
    }
    return _channelArr.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZGLSearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZGLSearchVC_ZGLSearchTableViewCell"];
    if (_channelArr.count > 0) {
        cell.searchWebModel = _channelArr[indexPath.row];
    } else {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"soycell"];
        cell.backgroundColor = foreColor;
        cell.textLabel.text = @"暂无相关搜索";
        cell.textLabel.textColor = naviColor;
        cell.textLabel.textAlignment = 1;
        return cell;
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (_channelArr.count > 0) {
        ZGLSearchWebModel *model = _channelArr[indexPath.row];
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        self.signArr = [user arrayForKey:@"allOptions"].mutableCopy;
        for (NSDictionary *dic in _signArr) {
            if ([dic[@"title"] isEqualToString:model.name]) {
                NSString *type = dic[@"data_type"];
                if (type.length == 0) {
                    ZGLSubDetailsVC *detailsVC = [[ZGLSubDetailsVC alloc] init];
                    [self deleteIdsWith:dic with:detailsVC];
                    [self.navigationController pushViewController:detailsVC animated:YES];
                }
                if ([type isEqualToString:@"topic"]) {
                    ZGLTopicTypeVC *topicVC = [[ZGLTopicTypeVC alloc] init];
                    [self handleTopicModelWithDic:dic with:topicVC];
                    [self.navigationController pushViewController:topicVC animated:YES];
                }
                if ([type isEqualToString:@"photo_news"]) {
                    ZGLTablePicVC *picVC = [[ZGLTablePicVC alloc] init];
                    [self handlePicVCModelWithDic:dic with:picVC];
                    [self.navigationController pushViewController:picVC animated:YES];
                }
                if ([type isEqualToString:@"rss"]) {
                    ZGLSubDetailsVC *detailsVC = [[ZGLSubDetailsVC alloc] init];
                    [self deleteIdsWith:dic with:detailsVC];
                    [self.navigationController pushViewController:detailsVC animated:YES];
                }
                if ([type isEqualToString:@"photo"]) {
                    ZGLPhotoVC *photoVC = [[ZGLPhotoVC alloc] init];
                    [self addAllPhotoWith:dic with:photoVC];
                    [self.navigationController pushViewController:photoVC animated:YES];
                }
                if ([type isEqualToString:@"episode"]) {
                    ZGLEpisodeVC *news = [[ZGLEpisodeVC alloc] init];
                    news.title = dic[@"title"];
                    [self episodeTypeHandleDataWith:dic with:news];
                    [self.navigationController pushViewController:news animated:YES];
                }
            }
        }
    }
    [_resultView removeFromSuperview];
}
- (void)episodeTypeHandleDataWith:(NSDictionary *)dic with:(ZGLEpisodeVC *)news {
    [ZGLHTTPTOOL GETWithURL:dic[@"api_url"] withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        NSMutableArray *arr = result[@"data"][@"articles"];
        news.viewUrl = result[@"data"][@"ipadconfig"][@"pages"][0][@"diy"][@"bgimage_url"];
        news.nextUrl = result[@"data"][@"info"][@"next_url"];
        NSMutableArray *modelArr = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dict in arr) {
            ZGLSubDetModel *model = [ZGLSubDetModel modWithDic:dict];
            if (model.auther_name.length > 0) {
                [modelArr addObject:model];
            }
        }
        news.modelArr = modelArr;
    } withFail:^(id result) {
        
    }];
}

- (void)addAllPhotoWith:(NSDictionary *)dic with:(ZGLPhotoVC *)photoVC {
    [ZGLHTTPTOOL GETWithURL:dic[@"api_url"] withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        photoVC.yuanDic = dic;
        photoVC.urlStr = result[@"data"][@"info"][@"next_url"];
        photoVC.yuanUrl = dic[@"api_url"];
        NSMutableArray *arr = result[@"data"][@"articles"];
        NSMutableArray *modelArr = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dict in arr) {
            ZGLPicVCModel *model  = [ZGLPicVCModel modWithDic:dict];
            [modelArr addObject:model];
        }
        photoVC.photoArr = modelArr;
    } withFail:^(id result) {
        
    }];
    
}

- (void)deleteIdsWith:(NSDictionary *)dic with:(ZGLSubDetailsVC *)detailsVC {
    [ZGLHTTPTOOL GETWithURL:dic[@"api_url"] withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        detailsVC.yuanDic = dic;
        detailsVC.titleUrl = result[@"data"][@"ipadconfig"][@"pages"][0][@"diy"][@"bgimage_url"];
        NSMutableArray *arr = result[@"data"][@"articles"];
        NSMutableArray *modelArr = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dict in arr) {
            ZGLSubDetModel *model = [ZGLSubDetModel modWithDic:dict];
            if (model.auther_name.length > 0) {
                [modelArr addObject:model];
            }
        }
        detailsVC.detListArr = modelArr;
    } withFail:^(id result) {
    }];
}


- (void)handleTopicModelWithDic:(NSDictionary *)dic with:(ZGLTopicTypeVC *)topicVC {
    [ZGLHTTPTOOL GETWithURL:dic[@"api_url"] withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        topicVC.dateStr = result[@"data"][@"list"][0][@"date"];
        NSMutableArray *arr = result[@"data"][@"list"][0][@"topic_list"];
        NSMutableArray *modelArr = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dict in arr) {
            ZGLTopicDetModel *model1 = [ZGLTopicDetModel modWithDic:dict];
            [modelArr addObject:model1];
        }
        topicVC.topicModelArr = modelArr;
    } withFail:^(id result) {
        
    }];
}

- (void)handlePicVCModelWithDic:(NSDictionary *)dic with:(ZGLTablePicVC *)tableVC {
    [ZGLHTTPTOOL GETWithURL:dic[@"api_url"] withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        tableVC.yuanUrlStr = dic[@"api_url"];
        tableVC.urlStr = result[@"data"][@"info"][@"next_url"];
        NSMutableArray *arr = result[@"data"][@"articles"];
        NSMutableArray *modelArr = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dict in arr) {
            ZGLPicVCModel *model  = [ZGLPicVCModel modWithDic:dict];
            [modelArr addObject:model];
        }
        tableVC.picModelArr = modelArr;
    } withFail:^(id result) {
        
    }];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view1 = [[UIView alloc] init];
    view1.backgroundColor = backColor;
        [view1 setFrame:CGRectMake(0, 0, ScaleX * 375, ScaleY * 20)];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScaleX * 375, ScaleY * 20)];
        label.textAlignment = 1;
        label.textColor = [UIColor lightGrayColor];
        label.font = [UIFont systemFontOfSize:11];
        if (0 == section) {
            label.text = @"频道";
        }
        [view1 addSubview:label];
    
    return view1;
}


#pragma mark - setSearchBar
- (void)setSearchBar {
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, ScaleX * 300, ScaleY * 28)];
    _searchBar.backgroundImage = [UIImage imageNamed:@"btu_search"];
    _searchBar.placeholder = @"搜索";
    _searchBar.delegate = self;
    UIBarButtonItem *searchButton = [[UIBarButtonItem alloc]initWithCustomView:_searchBar];
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObject:searchButton];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zaihufanhui"] style:(UIBarButtonItemStyleDone) target:self action:@selector(leftBarButtonItem:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void)leftBarButtonItem:(UIBarButtonItem *)button {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
    _resultView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, ScaleX * 375, ScaleY * 603)];
    _resultView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_resultView];
    [self createTableView];
    [_searchBar setShowsCancelButton:YES animated:YES];
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    _searchUrl = searchText;
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    [_searchBar setShowsCancelButton:NO animated:YES];
    searchBar.text = nil;
    [_resultView removeFromSuperview];
    [_searchBar resignFirstResponder];
}

#pragma mark - setTitleView
- (void)setTitleView {
    self.titleView = [[ZGLSearchTitleView alloc] initWithFrame:CGRectMake(0, 64, ScaleX * 375, ScaleY * 40)];
    [self.titleView.goodsButton addTarget:self action:@selector(button:) forControlEvents:(UIControlEventTouchUpInside)];
    self.titleView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.titleView.layer.borderWidth = 0.3;
    [self.titleView.channelButton addTarget:self action:@selector(button:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.titleView];
}

#pragma mark - button点击界面跳转
- (void)button:(UIButton *)button {
    if ([button.titleLabel.text isEqualToString:@"精品"]) {
        [self.searchCollectionView setContentOffset:CGPointMake(0, 0) animated:YES];
        [UIView animateWithDuration:0.1 animations:^{
            [self.titleView.lineLabel  setFrame:CGRectMake(0, self.titleView.frame.size.height - ScaleY * 2, ScaleX * 375 / 2, ScaleY * 2)];
        }];
        [self.titleView.goodsButton setSelected:YES];
        [self.titleView.channelButton setSelected:NO];
        ZGLChannelCollectionViewCell *cell = (ZGLChannelCollectionViewCell *)[_searchCollectionView cellForItemAtIndexPath:_tempIndex];
        if (cell.subOptionsTableView) {
            [cell.subOptionsTableView removeFromSuperview];
            [cell.button removeFromSuperview];
            cell.isCreate = NO;
        }
    } else {
        [self.searchCollectionView setContentOffset:CGPointMake(ScaleX * 375, 0) animated:YES];
        [UIView animateWithDuration:0.1 animations:^{
            [self.titleView.lineLabel  setFrame:CGRectMake(ScaleX * 375 / 2, self.titleView.frame.size.height - ScaleY * 2, ScaleX * 375 / 2, ScaleY * 2)];
        }];
        [self.titleView.goodsButton setSelected:NO];
        [self.titleView.channelButton setSelected:YES];
    }
}

#pragma mark - 创建collectionView
- (void)setCollectionView {
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    flow.itemSize = CGSizeMake(ScaleX * 375, ScaleY * (667 - 40) - 64);
    flow.scrollDirection = 1;
    flow.minimumLineSpacing = 0;
    self.searchCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64 + ScaleY * 40, ScaleX * 375, ScaleY * (667 - 40) - 64) collectionViewLayout:flow];
    self.searchCollectionView.delegate = self;
    self.searchCollectionView.dataSource = self;
    self.searchCollectionView.pagingEnabled = YES;
    [self.searchCollectionView registerClass:[ZGLGoodsCollectionViewCell class] forCellWithReuseIdentifier:@"ZGLSearchVC_ZGLGoodsCollectionViewCell"];
    [self.searchCollectionView registerClass:[ZGLChannelCollectionViewCell class] forCellWithReuseIdentifier:@"ZGLSearchVC_ZGLChannelCollectionViewCell"];
    [self.searchCollectionView addObserver:self forKeyPath:@"contentOffset" options:(NSKeyValueObservingOptionNew) context:nil];
    [self.view addSubview:self.searchCollectionView];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
    CGPoint point = [[change objectForKey:@"new"] CGPointValue];
    if (point.x > ScaleX * 187.5) {
        [UIView animateWithDuration:0.1 animations:^{
            [self.titleView.lineLabel  setFrame:CGRectMake(ScaleX * 375 / 2, ScaleY * (self.titleView.frame.size.height - 2), ScaleX * 375 / 2, ScaleY * 2)];
        }];
        [self.titleView.goodsButton setSelected:NO];
        [self.titleView.channelButton setSelected:YES];
    } else {
        [UIView animateWithDuration:0.1 animations:^{
            [self.titleView.lineLabel  setFrame:CGRectMake(0, ScaleY * (self.titleView.frame.size.height - 2), ScaleX * 375 / 2, ScaleY * 2)];
        }];
        [self.titleView.goodsButton setSelected:YES];
        [self.titleView.channelButton setSelected:NO];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setSearchBar];
    [self setTitleView];
    [self setCollectionView];
   
    // Do any additional setup after loading the view.
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [_searchBar setShowsCancelButton:NO animated:YES];
    NSString *str = @"http://search.myzaker.com/api/?c=main&act=getApps&keyword=";
    NSMutableString *strUrl = [str stringByAppendingString:_searchUrl].mutableCopy;
    [strUrl appendString:@"&app_ids=660%2C4%2C13%2C10318%2C11465%2C7%2C10644%2C3%2C1%2C14%2C2%2C972%2C959%2C10802%2C11464%2C11582%2C11846%2C10719%2C11794%2C1147%2C10530%2C9%2C12080%2C10501%2C12028%2C710%2C1156%2C11888%2C969%2C12040%2C720%2C406%2C310000"];
    NSString *striEncoding = [strUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [ZGLHTTPTOOL GETWithURL:striEncoding withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        _channelArr = [NSMutableArray arrayWithCapacity:0];
        NSMutableArray *arr = result[@"data"][@"list"];
        NSMutableArray *modelArr = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dic in arr) {
            ZGLSearchWebModel *model = [ZGLSearchWebModel modWithDic:dic];
            [modelArr addObject:model];
        }
        _channelArr = modelArr;
        [self.resultTableview reloadData];
    } withFail:^(id result) {
        
    }];
    [searchBar resignFirstResponder];
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
   
    if (0 == indexPath.item) {
        ZGLGoodsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZGLSearchVC_ZGLGoodsCollectionViewCell" forIndexPath:indexPath];
        cell.delegate = self;
        return cell;
    } else {
        ZGLChannelCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZGLSearchVC_ZGLChannelCollectionViewCell" forIndexPath:indexPath];
        cell.delegate = self;
        _tempIndex = indexPath;
        return cell;
    }
}

- (void)passHeadModelArr:(NSMutableArray *)arr {
    ZGLNewChannelVC *newChannelVC = [[ZGLNewChannelVC alloc] init];
    newChannelVC.modelArr = [NSMutableArray arrayWithArray:arr];
    [self.navigationController pushViewController:newChannelVC animated:YES];
}
- (void)passModelArr:(ZGLOptionsModel *)model {
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:model.api_url forKey:@"api_url"];
    [dic setObject:model.title forKey:@"title"];
    [dic setObject:model.large_pic forKey:@"large_pic"];
    [dic setObject:model.block_color forKey:@"block_color"];
    [dic setObject:model.data_type forKeyedSubscript:@"data_type"];
    if (model.data_type.length == 0) {
        ZGLSubDetailsVC *detailsVC = [[ZGLSubDetailsVC alloc] init];
        [self deleteIdsWith:dic with:detailsVC];
        [self.navigationController pushViewController:detailsVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"topic"]) {
        ZGLTopicTypeVC *topicVC = [[ZGLTopicTypeVC alloc] init];
        [self handleTopicModelWithDic:dic with:topicVC];
        [self.navigationController pushViewController:topicVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"photo_news"]) {
        ZGLTablePicVC *picVC = [[ZGLTablePicVC alloc] init];
        [self handlePicVCModelWithDic:dic with:picVC];
        [self.navigationController pushViewController:picVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"rss"]) {
        ZGLSubDetailsVC *detailsVC = [[ZGLSubDetailsVC alloc] init];
        [self deleteIdsWith:dic with:detailsVC];
        [self.navigationController pushViewController:detailsVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"photo"]) {
        ZGLPhotoVC *photoVC = [[ZGLPhotoVC alloc] init];
        [self addAllPhotoWith:dic with:photoVC];
        [self.navigationController pushViewController:photoVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"episode"]) {
        ZGLEpisodeVC *news = [[ZGLEpisodeVC alloc] init];
        news.title = dic[@"title"];
        [self episodeTypeHandleDataWith:dic with:news];
        [self.navigationController pushViewController:news animated:YES];
    }

}
- (void)passDic:(ZGLOptionsModel *)model {
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:model.api_url forKey:@"api_url"];
    [dic setObject:model.title forKey:@"title"];
    [dic setObject:model.large_pic forKey:@"large_pic"];
    [dic setObject:model.block_color forKey:@"block_color"];
    [dic setObject:model.data_type forKeyedSubscript:@"data_type"];
    if (model.data_type.length == 0) {
        ZGLSubDetailsVC *detailsVC = [[ZGLSubDetailsVC alloc] init];
        [self deleteIdsWith:dic with:detailsVC];
        [self.navigationController pushViewController:detailsVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"topic"]) {
        ZGLTopicTypeVC *topicVC = [[ZGLTopicTypeVC alloc] init];
        [self handleTopicModelWithDic:dic with:topicVC];
        [self.navigationController pushViewController:topicVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"table"]) {
        ZGLTablePicVC *picVC = [[ZGLTablePicVC alloc] init];
        [self handlePicVCModelWithDic:dic with:picVC];
        [self.navigationController pushViewController:picVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"rss"]) {
        ZGLSubDetailsVC *detailsVC = [[ZGLSubDetailsVC alloc] init];
        [self deleteIdsWith:dic with:detailsVC];
        [self.navigationController pushViewController:detailsVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"photo"]) {
        ZGLPhotoVC *photoVC = [[ZGLPhotoVC alloc] init];
        [self addAllPhotoWith:dic with:photoVC];
        [self.navigationController pushViewController:photoVC animated:YES];
    }
    if ([model.data_type isEqualToString:@"episode"]) {
        ZGLEpisodeVC *news = [[ZGLEpisodeVC alloc] init];
        news.title = dic[@"title"];
        [self episodeTypeHandleDataWith:dic with:news];
        [self.navigationController pushViewController:news animated:YES];
    }
}
- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBarHidden = NO;
    self.view.backgroundColor = backColor;
    self.resultTableview.backgroundColor = backColor;
    if (_resultTableview) {
        [self.resultTableview reloadData];
    }
    self.searchCollectionView.backgroundColor = backColor;
    [self.searchCollectionView reloadData];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
